home *** CD-ROM | disk | FTP | other *** search
- /* Rotate Process.c - © 1992 Shane D. Looker
-
- This is a GNE filter which will look for the Ctrl-Option right-arrow
- key press. When it finds it, it will rotate to the next process in the
- process list. Wrapping is done when the end of the list is found and
- faceless background apps return an error so are avoided.
- */
-
- #include <processes.h>
-
-
- pascal void main(void);
-
- #define kMaximumBackgroundOnlyApps 100
-
- #undef __DEBUG__
-
- pascal void main(void)
- {
- Ptr addr;
- Ptr globalP;
- long rD0;
- EventRecord *rA1;
-
- asm {
- MOVEM.L A2-A5/D1-D7, -(A7) /* Save the non-volitle registers */
- MOVE.L d0, rD0 /* Get to d0 & a0 easily */
- MOVE.L a1, rA1
- }
-
- addr = *(Ptr *)(((Ptr)&main) - 8); /* Get the address of last filter */
- globalP = *(Ptr *)(((Ptr)&main) - 4); /* Get the address of global storage */
- /* The structure is:
- long last filter address;
- Ptr globalDataSpace; */
- if ((rA1)->what == keyDown)
- {
- if (((((rA1)->message & keyCodeMask) >> 8) == 0x7C) && /* Right arrow key */
- ((rA1)->modifiers & controlKey) && ((rA1)->modifiers & optionKey))
- {
- ProcessSerialNumber thePSN;
- short err;
- short attemptCount = 0;
-
- err = GetCurrentProcess(&thePSN);
- #ifdef __DEBUG__
- if (err)
- DebugStr("\PError with GetCurrentProcess");
- #endif
-
- do {
- err = GetNextProcess(&thePSN);
- if (err)
- {
- thePSN.lowLongOfPSN = kNoProcess;
- err = GetNextProcess(&thePSN);
- #ifdef __DEBUG__
- if (err)
- DebugStr("\PError with GetNextProcess");
- #endif
- }
-
- err = SetFrontProcess(&thePSN);
- } while (err && (attemptCount++ < kMaximumBackgroundOnlyApps));
-
- if (err == 0)
- (rA1)->what = nullEvent; /* Kill the key event so nobody gets confused */
- #ifdef __DEBUG__
- else
- DebugStr("\PError with SetFrontProcess");
- #endif
- }
- }
-
- asm {
- MOVEM.L (A7)+, A2-A5/D1-D7 /* Restore the non-volitle registers */
- MOVE.L rD0, d0
- MOVE.L rA1, a1
- MOVE.L addr, A0
- UNLK A6
- JMP (A0)
- };
- }